﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTDeviceUsingService : ServiceHandle, IRPTDeviceUsing
    {
        #region IRPTDeviceUsing Members

        public OperationResult<List<tb_RPT_DeviceUsing>> GetAllRPTDeviceUsing()
        {
            OperationResult<List<tb_RPT_DeviceUsing>> result = new OperationResult<List<tb_RPT_DeviceUsing>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_RPT_DeviceUsing> list = new List<tb_RPT_DeviceUsing>();
            try
            {
                list = dataContext.GetAllRPTDeviceUsing();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_DeviceUsing>> GetRPTDeviceUsingByDeviceId(int deviceId)
        {
            OperationResult<List<tb_RPT_DeviceUsing>> result = new OperationResult<List<tb_RPT_DeviceUsing>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_RPT_DeviceUsing> list = new List<tb_RPT_DeviceUsing>();
            try
            {
                list = dataContext.GetRPTDeviceUsingByDeviceId(deviceId);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_DeviceUsing>> GetRPTDeviceUsingByUsingDate(DateTime UsingDate1, DateTime UsingDate2)
        {
            OperationResult<List<tb_RPT_DeviceUsing>> result = new OperationResult<List<tb_RPT_DeviceUsing>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_RPT_DeviceUsing> list = new List<tb_RPT_DeviceUsing>();
            try
            {
                list = dataContext.GetRPTDeviceUsingByUsingDate(UsingDate1, UsingDate2);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

 
        public OperationResult<List<tb_RPT_DeviceUsing>> GetRPTDeviceUsingByTester(string tester)
        {
            OperationResult<List<tb_RPT_DeviceUsing>> result = new OperationResult<List<tb_RPT_DeviceUsing>>();
            ConcreteDaoDataContext dataContext = getDateContext();
            List<tb_RPT_DeviceUsing> list = new List<tb_RPT_DeviceUsing>();
            try
            {
                list = dataContext.GetRPTDeviceUsingByTester(tester);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_DeviceUsing> GetRPTDeviceUsingById(int id)
        {
            OperationResult<tb_RPT_DeviceUsing> result = new OperationResult<tb_RPT_DeviceUsing>();
            ConcreteDaoDataContext dataContext = getDateContext();
            tb_RPT_DeviceUsing deviceUsing;
            try
            {
                deviceUsing = dataContext.GetRPTDeviceUsingById(id);
                if (deviceUsing == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = deviceUsing;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_DeviceUsing> CreateRPTDeviceUsing(tb_RPT_DeviceUsing entity)
        {
            OperationResult<tb_RPT_DeviceUsing> result = new OperationResult<tb_RPT_DeviceUsing>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateRPTDeviceUsing(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_DeviceUsing> ModifyRPTDeviceUsing(tb_RPT_DeviceUsing entity)
        {
            OperationResult<tb_RPT_DeviceUsing> result = new OperationResult<tb_RPT_DeviceUsing>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyRPTDeviceUsing(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_DeviceUsing> DeleteRPTDeviceUsing(tb_RPT_DeviceUsing entity)
        {
            OperationResult<tb_RPT_DeviceUsing> result = new OperationResult<tb_RPT_DeviceUsing>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteRPTDeviceUsing(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion

         
    }
}
